<template>
    <header class="header">
        <div class="header-container">
            <div class="header-left">
                <h1>微信开放社区</h1>
            </div>
            <nav class="main-nav">
                <ul>
                    <li><a href="#" class="nav-item active">交流专区</a></li>
                    <li><a href="#" class="nav-item">服务市场</a></li>
                    <li><a href="#" class="nav-item">微信学堂</a></li>
                    <li><a href="#" class="nav-item">文档</a></li>
                </ul>
            </nav>
            <div class="header-right">
                <input type="text" placeholder="搜索你想要的内容" class="search-input" />
                <div class="user-area">
                    <span v-if="user && user.username">{{ user.username }}</span>
                    <button v-if="user && user.username" @click="handleLogout" class="logout-button">退出</button>
                    <router-link v-else to="/login" class="login-button">登录</router-link>
                </div>
            </div>
        </div>
    </header>
</template>

<script setup>
import { defineProps } from 'vue';
import { RouterLink } from 'vue-router';

const props = defineProps({
    user: Object,
    handleLogout: Function
});
</script>

<style scoped>
.header {
    background-color: #ffffff;
    color: #333;
    padding: 0.4rem 0;
    display: flex;
    align-items: center;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid #f5f5f5;
}

.header-container {
    width: 100%;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.header h1 {
    font-size: 1.4rem;
    margin: 0;
    color: #07c160;
    font-weight: 500;
    letter-spacing: 0.1px;
}

.main-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 2.5rem;
}

.nav-item {
    text-decoration: none;
    color: #555;
    font-weight: 400;
    padding-bottom: 5px;
    position: relative;
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.nav-item:hover {
    color: #07c160;
}

.nav-item.active {
    color: #07c160;
    font-weight: 500;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0px;
    width: 30%;
    height: 1px;
    background-color: #07c160;
    border-radius: 0.5px;
    transition: width 0.3s ease;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-input {
    padding: 0.4rem 0.9rem;
    border: 1px solid #e5e5e5;
    border-radius: 16px;
    font-size: 0.8rem;
    width: 200px;
    background-color: #f9f9f9;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.03);
    transition: all 0.3s ease;
}

.search-input:focus {
    border-color: #07c160;
    box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.04), 0 0 0 2px rgba(7, 193, 96, 0.06);
    outline: none;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: #555;
}

.login-button,
.logout-button {
    padding: 0.3rem 0.8rem;
    background-color: #f5f5f5;
    color: #555;
    border: none;
    border-radius: 2px;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 400;
    transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.login-button:hover,
.logout-button:hover {
    background-color: #ededed;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.01);
}
</style>